package com.serene.im.controller;

import com.serene.im.enums.HttpCode;
import com.serene.im.utils.JsonResult;
import com.serene.im.pojo.ImChatMsgLogs;
import com.serene.im.service.ImChatMsgLogsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * m_chat聊天记录 前端控制器
 *
 * @author serence
 * @date 2021/3/18 15:55
 */

@RestController
@RequestMapping("/imChatMsgLogs/")
public class ImChatMsgLogsController {

    @Autowired
    private ImChatMsgLogsService imChatMsgLogsService;

    /**
     * 根据发送者id和接受者id查询好友聊天记录
     *
     * @param sendId    发送者id
     * @param receiveId 接受者id
     * @return
     */
    @RequestMapping("selectFriendLogsList")
    public JsonResult<Object> selectFriendLogsList(String sendId, String receiveId) {
        System.out.println("进入查询好友信息数据。。。");
        HttpCode httpCode = HttpCode.PARAM_VERIFICATION;
        if (StringUtils.isBlank(sendId) || StringUtils.isBlank(receiveId)) {
            return new JsonResult<Object>(null, httpCode);
        }
        //查询好友聊天记录
        List<ImChatMsgLogs> infoList = imChatMsgLogsService.queryFriendLogsList(sendId, receiveId);
        ImChatMsgLogs imChatMsgLogs = new ImChatMsgLogs();
        imChatMsgLogs.setSendId(sendId);
        imChatMsgLogs.setReceiveId(receiveId);
        imChatMsgLogsService.updateImChatMsgListById(imChatMsgLogs);
        return new JsonResult<Object>(infoList, HttpCode.SUCCESS);
    }

    /**
     * 根据群信息id查询群聊天记录
     *
     * @param groupInfoId 群id
     * @return
     */
    @RequestMapping("selectGroupLogsList")
    public JsonResult<Object> selectGroupLogsList(Integer groupInfoId) {
        System.out.println("进入查询群信息数据。。。。。。");
        HttpCode httpCode = HttpCode.PARAM_VERIFICATION;
        if (groupInfoId == null) {
            return new JsonResult<Object>(null, httpCode);
        }
        //根据群id查询群信息记录
        List<ImChatMsgLogs> infoList = imChatMsgLogsService.queryImChatMsgLogsListByGroupInfoId(groupInfoId);
        return new JsonResult<Object>(infoList, HttpCode.SUCCESS);
    }

}
